package com.zhl.datasource;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * Created by Administrator on 2019/4/18.
 * 引用配置的不同的数据库数据，创建不同的数据源
 */
@Configuration
public class DataSourceConfig {

    @Bean("mainDS")
    @ConfigurationProperties(prefix = "spring.datasource.main")
    @Primary
    public DataSource mainDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean("cmDS")
    @ConfigurationProperties(prefix = "spring.datasource.cm")
    @Primary
    public DataSource cmDataSource() {
        return DataSourceBuilder.create().build();
    }

}
